﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlarmClock.UI.Controls
{
    public partial class Check : UserControl
    {

        /// <summary>
        /// 是否选中
        /// </summary>
        bool isCheck = true;

        /// <summary>
        /// 枚举
        /// </summary>
        public enum CheckStyle
        {
            style1 = 0,
            style2 = 1,
            style3 = 2,
            style4 = 3,
            style5 = 4,
            style6 = 5
        }
        public Check()
        {
            InitializeComponent();


            //设置Style支持透明背景色并且双缓冲
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.Selectable, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.BackColor = Color.Transparent;

            this.Cursor = Cursors.Hand;
            this.Size = new Size(128, 128);
        }

        /// <summary>
        /// 是否被选中
        /// </summary>
        public bool Checked
        {
            set { isCheck = value; this.Invalidate(); }
            get { return isCheck; }
        }

        CheckStyle checkstyle = CheckStyle.style1;

        /// <summary>
        /// 状态
        /// </summary>
        public CheckStyle checkStyle_State
        {
            set { checkstyle = value; this.Invalidate(); }
            get { return checkstyle; }
        }


        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap bitMapOn = null;
            Bitmap bitMapOff = null;

            if (checkstyle == CheckStyle.style1)
            {
                bitMapOn = Properties.Resources.按钮_开启;
                bitMapOff = Properties.Resources.按钮_关闭;
            }
            else if(checkstyle == CheckStyle.style2)
            {
                bitMapOn = Properties.Resources.选择_已选择;
                bitMapOff = Properties.Resources.选择_未选择;
            }

            Graphics g = e.Graphics;
            Rectangle rec = new Rectangle(0, 0, this.Size.Width, this.Size.Height);

            if (isCheck) g.DrawImage(bitMapOn, rec);
            else g.DrawImage(bitMapOff, rec);
        }

        private void MyCheckBox_Ctrl_Click(object sender, EventArgs e)
        {
            isCheck = !isCheck;
            this.Invalidate();
        }

    }
}
